package com.otaku.admin.controller;

import com.alibaba.fastjson.JSON;
import com.otaku.admin.dao.entity.SelfUserDetails;
import com.otaku.admin.service.SelfUserDetailsService;
import com.otaku.admin.util.ResultEnum;
import com.otaku.admin.util.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private SelfUserDetailsService userDetailsService;

    @RequestMapping("/register")
    public String register(SelfUserDetails userDetails){
        //因为只是简单注册，故只是对密码加密保存，其他就不添加进来了
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String EncryptedPassword = bCryptPasswordEncoder.encode(userDetails.getPassword());
        userDetails.setPassword(EncryptedPassword);
        LOGGER.info(EncryptedPassword);
        userDetailsService.register(userDetails);
        return JSON.toJSONString(ResultVO.result(ResultEnum.SUCCESS,true));
    }
}
